package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.BotYIzhanBean;
import com.example.myapplication.ShuJu.Re_News;
import com.example.myapplication.teenager.Hostel_DetailActivity;

import java.util.List;

public class BotYIzhanAdapter extends RecyclerView.Adapter<BotYIzhanAdapter.MyHolder>{
    private Context context;
    private List<BotYIzhanBean.RowsBean> list;

    public BotYIzhanAdapter(Context context, List<BotYIzhanBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public BotYIzhanAdapter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_hostel,null);
        return new BotYIzhanAdapter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull BotYIzhanAdapter.MyHolder holder, int position) {
        Glide.with(context).load(list.get(position).getCoverImgUrl()).into(holder.hostelImageView);
        holder.hostelImageView.setScaleType(ImageView.ScaleType.FIT_XY);
        holder.bedsTextView.setText("剩余男床位"+list.get(position).getBedsCountBoy());
        holder.bedsCountGirl.setText("剩余女床位"+list.get(position).getBedsCountGirl());
        holder.hostelNameTextView.setText(list.get(position).getName());
        holder.addressTextView.setText(list.get(position).getAddress());
        //点击进入站点详情
        holder.li_hostel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, Hostel_DetailActivity.class);
                intent.putExtra("RowsBeanID",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        ImageView hostelImageView;
        TextView hostelNameTextView;
        TextView bedsTextView;
        TextView bedsCountGirl;
        TextView addressTextView;
        Button expandButton;
        RelativeLayout li_hostel;
        public MyHolder(@NonNull View itemView) {
            super(itemView);
            hostelImageView = itemView.findViewById(R.id.hostelImageView);
            addressTextView = itemView.findViewById(R.id.addressTextView);
            hostelNameTextView = itemView.findViewById(R.id.hostelNameTextView);
            bedsTextView = itemView.findViewById(R.id.bedsTextView);
            bedsCountGirl = itemView.findViewById(R.id.bedsCountGirl);
            expandButton = itemView.findViewById(R.id.expandButton);
            li_hostel = itemView.findViewById(R.id.li_hostel);
        }
    }
}


